<template>
  <el-row class="panel-group" :gutter="15">
    <el-col class="card-panel-col">
      <div class="card-panel">
        <span class="downloadTable">下载报表</span>
        <div style="padding:15px;">
          <el-form :inline="true" class="demo-form-inline">
            <el-form-item>
              <slot name='tabs' />
            </el-form-item>
            <el-form-item>
              <el-date-picker v-model="datePicker" type="daterange" align="left" unlink-panels format="yyyy-MM-dd" value-format="timestamp" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions" @change="pickerChange" :clearable="false" />
            </el-form-item>
          </el-form>
          <!-- <div class="nodata" v-if="$parent.chartData.time.length === 0">暂无统计数据</div> -->
          <line-chart :chartdata="$parent.chartData" ref="chart" :typeLine="setline" style="position: relative;"></line-chart>
        </div>
      </div>
    </el-col>
  </el-row>
</template>

<script>
import LineChart from './LineChart';

export default {
  name: 'ToDo',
  data () {
    return {
      datePicker: [],
      pickerOptions: {
        disabledDate: time => {
          return time.getTime() > Date.now(); // 结束时间大于开始时间且小于当前时间
        },
        shortcuts: [{
          text: '最近一周',
          onClick (picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick (picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }]
      }
    };
  },
  components: {
    LineChart
  },
  props: {
    value: {
      type: String
    }
  },
  computed: {
    setline: {
      get: function () {
        return this.value;
      },
      set: function (val) {
        this.$emit('input', val);
      }
    }
  },
  created () {
    const end = new Date();
    const start = new Date();
    start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
    this.datePicker = [+start, +end];
    this.$parent.handleSetLineChartData(this.setline, this.datePicker);
  },
  methods: {
    pickerChange () {
      this.$parent.handleSetLineChartData(this.setline, this.datePicker, 'manually');
    }
  }
};
</script>

<style lang="less" scoped>
.panel-group {
  .nodata {
    line-height: 300px;
    position: absolute;
    left: 20px;
    right: 20px;
    top: 80px;
    bottom: 30px;
    background-color: rgba(254, 254, 254, 0.7);
    text-align: center;
    z-index: 999;
  }
  .card-panel-col {
    margin-bottom: 15px;
  }
  .X-card-panel {
    height: 60px;
    background-color: #fff;
  }
  .card-panel {
    cursor: pointer;
    font-size: 12px;
    position: relative;
    overflow: hidden;
    color: #666;
    background: #fff;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, 0.05);
    border-color: rgba(0, 0, 0, 0.05);
    .downloadTable {
      position: absolute;
      right: 20px;
      top: 20px;
      color: #36a3f7;
      font-size: 14px;
    }
    &:hover {
      .card-panel-icon-wrapper {
        color: #fff;
      }
      .icon-people {
        background: #40c9c6;
      }
      .icon-message {
        background: #36a3f7;
      }
      .icon-money {
        background: #f4516c;
      }
      .icon-shoppingCard {
        background: #34bfa3;
      }
    }
    .icon-people {
      color: #40c9c6;
    }
    .icon-message {
      color: #36a3f7;
    }
    .icon-money {
      color: #f4516c;
    }
    .icon-shoppingCard {
      color: #34bfa3;
    }
    .card-panel-icon-wrapper {
      float: left;
      margin: 14px 0 0 14px;
      padding: 16px;
      transition: all 0.38s ease-out;
      border-radius: 6px;
    }
    .card-panel-icon {
      float: left;
      font-size: 35px;
    }
    .card-panel-description {
      float: left;
      margin: 26px;
      .card-panel-text {
        line-height: 18px;
        color: rgba(0, 0, 0, 0.45);
        font-size: 16px;
        margin-bottom: 12px;
      }
      .card-panel-num {
        font-size: 24px;
      }
    }
  }
}
</style>
